<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
    <title>我的订单</title>
    <link rel="stylesheet" href="__PUBLIC__/Home/css/memberOrder.css">
    <include file="Public/common_js"/>
</head>
<body>
<div class="warp">
    <!--订单类别-->
    <if condition="$view neq 7">
        <div class="member-order-category">
            <ul class="category-ui">
                <li <if condition="$view eq 6">class="active"</if> data-oid="6"><span>全部</span></li>
                <li <if condition="$view eq 3 ">class="active"</if> data-oid="3"><span>未支付</span></li>
                <li <if condition="$view eq 0 ">class="active"</if> data-oid="0"><span>待发货</span></li>
                <li <if condition="$view eq 10 ">class="active"</if> data-oid="10"><span>待收货</span></li>
                <li <if condition="$view eq 8 ">class="active"</if> data-oid="8"><span>待评价</span></li>
            </ul>
        </div>
    </if>
    <!-- 订单列表 -->
    <div class="member-order-list">
    </div>
</div>
<div class="alert-popup askorder-reminder" style="display:none">
    <p style="display:block;">如果您的订单还没有发货，可以拨打 <span class="tel"></span>联络发货人。</p>
    <p><a href="javascript:void(0);" class="cancel">取消</a><a href="javascript:void(0);" class="confirm bdtel">拨打</a></p>
</div>
<div class="alert-popup operate-reminder" style="display:none">
    <p class="msg">是否取消订单？</p>
    <p><a href="javascript:void(0);" class="confirm">确定</a><a href="javascript:void(0);" class="cancel">取消</a></p>
</div>
<include file ="Public/subclass_menu"/>
<php>$kuaidiurl = get_url()</php>
<script type="text/javascript">
	var topUrls = [];
	var curAjaxModeId = {:I('view')};
    var kd_pre_url = "{$kuaidiurl[top]}{$kuaidiurl[host]}";
</script>    
<script type="text/javascript" src="__PUBLIC__/Home/js/memberOrder.js?v=201703030001"></script>
<script type="text/javascript">
	require(['subClassMain']);
    var _isAjaxProcess = false;
	var _passJson = {"o" : null, "orderId" : null, "stat" : null};
	var _isFirst = true;
	function askOrder(telNumber){
		$(".askorder-reminder .tel").html(telNumber);
		$(".askorder-reminder .bdtel").attr("href", "tel://"+telNumber);
		_global.promote.popup(".askorder-reminder");
	}
	// 成功时候执行的方法
	function opSuccess(){
		var isDel = false;
		if(curAjaxModeId == 6 || curAjaxModeId == 7){
			var parent = $(_passJson["o"]).parents(".operate-position");
			var bgParent = $(_passJson["o"]).parents(".member-order-ycone");
			if(_passJson["stat"] == 3){
				isDel = true;
			}else if(_passJson["stat"] == 1){						
				parent.html(parent.find(".next-step").html());
				bgParent.find(".member-order-state").html("失效");
			}else if(_passJson["stat"] == 2){
				parent.html(parent.find(".next-step").html());
				bgParent.find(".member-order-state").html("待评价");
			}
		}else{
			isDel = true;
		}
		if(isDel){
			$(_passJson["o"]).parents('.member-order-ycone').remove();
		}
	}
	function opreateOrder(o, orderId, stat){
		_passJson["o"] = o;
		_passJson["orderId"] = orderId;
		_passJson["stat"] = stat;
		if(stat == 1){			
			$(".operate-reminder .msg").html("是否取消订单？");
		}else if(stat == 2){
			$(".operate-reminder .msg").html("是否确认收货？");
		}else if(stat == 3){
			$(".operate-reminder .msg").html("是否删除订单？");
		}
				
		_global.promote.popup(".operate-reminder", !_isFirst);
		
		if(_isFirst){
			_isFirst = false;
			$(".operate-reminder .confirm").click(function(e){
				ajaxOpreateOrder(_passJson["o"], _passJson["orderId"], _passJson["stat"]);
			});
		}		
	}
	
    function ajaxOpreateOrder(o, orderId, stat){
        if(_isAjaxProcess) return;
        _isAjaxProcess = true;
        _global.promote.loadPopup("正在处理中...");
        $.ajax({
            type: "POST",
            url: "{:url('Member/cancelOrder')}",
            data: { "order_id": orderId ,"stat": stat },
            dataType: "json",
            success: function (rs) {
                _global.promote.removeLoad();
                if(rs.stat)  {
                    opSuccess();
                }
                _global.promote.alertPopup(rs.msg);
                _isAjaxProcess = false;
            },
            error: function () {
                _global.promote.removeLoad();
                _global.promote.alertPopup('服务器异常，请稍后重试！');
                _isAjaxProcess = false;
            }
        });
    }
</script>
</body>
</html>
